﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PalcoCentral
{
    public partial class pcSelectPessoa : Form
    {
        public pcSelectPessoa()
        {
            InitializeComponent();

        }

        private void listaPessoas_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            this.saveSPButton.PerformClick();
        }

        private void pcSelectPessoa_Load(object sender, EventArgs e)
        {
            searchSelectPessoa.PerformClick();
        }

        private void searchSelectPessoasET_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                searchSelectPessoa.PerformClick();
            }
        }

        private void searchSelectPessoa_Click(object sender, EventArgs e)
        {
            Library.OperationStatus os = Database.PersonDBAdapter.getInstance().searchPersons(searchSelectPessoaET.Text);
            if (os.sucess)
            {
                List<Database.person> res = (List<Database.person>)os.res;
                listaSelectPessoa.DataSource = res;
                listaSelectPessoa.Update();
                if (res != null && res.Count > 0)
                {
                    //personDB.DataSource = res;

                }
                else
                {
                    MessageBox.Show("Não forma encontrados resultados.");
                    //No Results Found
                }

            }
        }

        private void saveSPButton_Click(object sender, EventArgs e)
        {
            Database.person person = (Database.person)listaSelectPessoa.SelectedItem;
            if (person == null)
            {
                return;
            }
            selectedPerson = person;
            cancelSPButton.PerformClick();
        }

        private void cancelSPButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        public Database.person selectedPerson // retrieving a value from
        {
            get;
            set;
        }

    }
}
